﻿using System.Collections.Generic;
using RayDen.Library.Core.Primitives;
using RayDen.RayEngine.Core.Types;

namespace RayDen.RayEngine.Scene
{

    public enum ScenePrimitiveType
    {
        Solid,
        Light,
        Volume,
        Gizmo
    }

    public interface IIntersectionEntity
    {
        Vector Direction { get; }
        float Pdf { get; }


    }


    public interface IScenePrimitive
    {
        int ID { get; set; }
        ScenePrimitiveType PrimitiveType { get; }
        bool OwnsIndex(uint index);

        //TODO:
        //Transform methods object space <->world space
        /*
         On Hit Method with iray and rayhit data as input, and object specific entity as output (Bsdf, VolumetricMaterial, LightSourceMaterial)
         */
        // void OnHit(ref IRay ray,ref RayHit hit, ref ISpectrum inputRadiance, out IIntersectionEntity);
    }

    public abstract class ScenePrimitive<TPrimitive, TInfo> : IScenePrimitive
    {
        private static int IDCurrent = 1;

        public TPrimitive Primitive;
        public TInfo Material;

        protected HashSet<uint> indexes;
        public int ID { get; set; }

        public abstract ScenePrimitiveType PrimitiveType { get; }

        protected ScenePrimitive(TPrimitive prim, TInfo mat)
        {
            ID = -1;
            this.Primitive = prim;
            this.Material = mat;
            indexes = new HashSet<uint>();
        }

        public virtual TPrimitive1 GetPrimitive<TPrimitive1>() where TPrimitive1 : class
        {
            return Primitive as TPrimitive1;
        }

        public virtual TInfo1 GetMaterial<TInfo1>()
            where TInfo1 : class
        {
            return Material as TInfo1;
        }

        public virtual bool OwnsIndex(uint index)
        {
            return indexes.Contains(index);
        }


    }
}
